<template>
	<view class="content">
		<view class="input-group">
			<view class="input-row border">
				<text class="title">账号：</text>
				<input class="uni-input" type="text" placeholder="请输入账号" value="" v-model="username"/>
			</view>
			<view class="input-row">
				<text class="title">密码：</text>
				<input class="uni-input" type="password" placeholder="请输入密码" value="" v-model="password"/>
			</view>
			<view class="input-row">
				<label style="color: red;">{{error}}</label>
			</view>
		</view>
		<view class="btn-row">
			<button type="primary" class="primary" @tap="bindLogin">登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				error:""
				
			}
		},
		onLoad:function(e){
			console.log("进入login");
			console.log(e);
		},
		methods: {
			bindLogin:function(e){
				this.error="";
				const data = {
					client_id:'d3ce0d85007b401cba4ea872cec42e38 ',
					client_secret:'yhRh1QmfjB65I4d8GtfYGg3V34K69QIL',
					grant_type:'password',
					scope:'read',
					username: this.username,
					password: this.password
				};
				var access_token='1',refresh_token='1';
				uni.request({
					url: getApp().globalData.oauth_service_url+"/oauth/token?client_id=d3ce0d85007b401cba4ea872cec42e38&client_secret=yhRh1QmfjB65I4d8GtfYGg3V34K69QIL&grant_type=password&scope=read&username="+this.username+"&password="+this.password,
					method: 'POST',
					data: data,
					success: res => {
						console.log(res);
						if(res.statusCode==200){
							access_token=res.data.access_token;
							refresh_token=res.data.refresh_token;
							if(access_token!=null){
								uni.navigateTo({
									url: '../index/index?access_token='+access_token+'&username='+this.username,
									success: res => {},
									fail: () => {},
									complete: () => {}
								});
							}
						}else{
							this.error="验证异常，请重新输入！";
						}
					},
					fail: res => {
					},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>

</style>
